package com.buaa.divinationmaster.model;

import java.io.Serializable;
import java.util.List;

/**
 * 雷诺曼占卜结果模型
 */
public class LenormandReading implements Serializable {
    private String question;
    private String spreadType;
    private List<LenormandCard> drawnCards;
    private String interpretation;
    private String timeline;
    private String advice;
    private long timestamp;
    
    public LenormandReading() {}
    
    public LenormandReading(String question, String spreadType, List<LenormandCard> drawnCards, 
                           String interpretation, String timeline, String advice) {
        this.question = question;
        this.spreadType = spreadType;
        this.drawnCards = drawnCards;
        this.interpretation = interpretation;
        this.timeline = timeline;
        this.advice = advice;
        this.timestamp = System.currentTimeMillis();
    }
    
    // Getters and Setters
    public String getQuestion() { return question; }
    public void setQuestion(String question) { this.question = question; }
    
    public String getSpreadType() { return spreadType; }
    public void setSpreadType(String spreadType) { this.spreadType = spreadType; }
    
    public List<LenormandCard> getDrawnCards() { return drawnCards; }
    public void setDrawnCards(List<LenormandCard> drawnCards) { this.drawnCards = drawnCards; }
    
    public String getInterpretation() { return interpretation; }
    public void setInterpretation(String interpretation) { this.interpretation = interpretation; }
    
    public String getTimeline() { return timeline; }
    public void setTimeline(String timeline) { this.timeline = timeline; }
    
    public String getAdvice() { return advice; }
    public void setAdvice(String advice) { this.advice = advice; }
    
    public long getTimestamp() { return timestamp; }
    public void setTimestamp(long timestamp) { this.timestamp = timestamp; }
    
    /**
     * 生成卡牌数据字符串用于数据库存储
     */
    public String generateCardDataString() {
        if (drawnCards == null || drawnCards.isEmpty()) {
            return "";
        }
        
        StringBuilder data = new StringBuilder();
        for (int i = 0; i < drawnCards.size(); i++) {
            if (i > 0) data.append(",");
            LenormandCard card = drawnCards.get(i);
            data.append(card.getId()).append(":").append(card.getName());
        }
        return data.toString();
    }
    
    /**
     * 生成完整的解读文本
     */
    public String generateFullInterpretation() {
        StringBuilder full = new StringBuilder();
        full.append("【雷诺曼卡牌解读】\n\n");
        full.append("问题：").append(question).append("\n");
        full.append("牌阵：").append(spreadType).append("\n\n");
        
        full.append("【抽到的卡牌】\n");
        if (drawnCards != null) {
            for (int i = 0; i < drawnCards.size(); i++) {
                LenormandCard card = drawnCards.get(i);
                full.append("第").append(i + 1).append("张：").append(card.getName())
                    .append(" (").append(card.getSymbol()).append(")\n");
            }
        }
        full.append("\n");
        
        if (interpretation != null && !interpretation.isEmpty()) {
            full.append("【卡牌解读】\n").append(interpretation).append("\n\n");
        }
        
        if (timeline != null && !timeline.isEmpty()) {
            full.append("【时间线预测】\n").append(timeline).append("\n\n");
        }
        
        if (advice != null && !advice.isEmpty()) {
            full.append("【建议】\n").append(advice).append("\n");
        }
        
        return full.toString();
    }
}
